﻿<UserControl x:Class="Infrastructure.WpfClient.Controls.TextEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:controls="clr-namespace:Infrastructure.WpfClient.Controls"
             xmlns:converts="clr-namespace:Infrastructure.WpfClient.Converts"
             x:Name="textEditor"
             mc:Ignorable="d"              
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <converts:StringToXamlConverter x:Key="StringToXamlConverter"></converts:StringToXamlConverter>
        <Style TargetType="{x:Type Button}" x:Key="formatTextStyle">
            <Setter Property="FontFamily" Value="Arial"></Setter>
            <Setter Property="Width" Value="30"></Setter>
            <Setter Property="FontSize" Value ="14"></Setter>
            <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"></Setter>
        </Style>
        <Style TargetType="{x:Type Button}" x:Key="formatImageStyle">
            <Setter Property="Width" Value="30"></Setter>
            <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"></Setter>
        </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="DarkGray">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <ToolBar Name="mainToolBar" Height="30">
            <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Cut" ToolTip="Cut">
                <Image Source="..\Images\EditCut.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Copy" ToolTip="Copy">
                <Image Source="..\Images\EditCopy.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Paste" ToolTip="Paste">
                <Image Source="..\Images\EditPaste.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Undo" ToolTip="Undo">
                <Image Source="..\Images\EditUndo.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Redo" ToolTip="Redo">
                <Image Source="..\Images\EditRedo.png"></Image>
            </Button>
            <Button Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleBold" ToolTip="Bold">
                <TextBlock FontWeight="Bold">B</TextBlock>
            </Button>
            <Button Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleItalic" ToolTip="Italic">
                <TextBlock FontStyle="Italic" FontWeight="Bold">I</TextBlock>
            </Button>
            <Button Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleUnderline" ToolTip="Underline">
                <TextBlock TextDecorations="Underline" FontWeight="Bold">U</TextBlock>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.IncreaseFontSize" ToolTip="Grow Font">
                <Image Source="..\Images\CharacterGrowFont.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.DecreaseFontSize" ToolTip="Shrink Font">
                <Image Source="..\Images\CharacterShrinkFont.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleBullets" ToolTip="Bullets">
                <Image Source="..\Images\ListBullets.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleNumbering" ToolTip="Numbering">
                <Image Source="..\Images\ListNumbering.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignLeft" ToolTip="Align Left">
                <Image Source="..\Images\ParagraphLeftJustify.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignCenter" ToolTip="Align Center">
                <Image Source="..\Images\ParagraphCenterJustify.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignRight" ToolTip="Align Right">
                <Image Source="..\Images\ParagraphRightJustify.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignJustify" ToolTip="Align Justify">
                <Image Source="..\Images\ParagraphFullJustify.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.IncreaseIndentation" ToolTip="Increase Indent">
                <Image Source="..\Images\ParagraphIncreaseIndentation.png"></Image>
            </Button>
            <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.DecreaseIndentation" ToolTip="Decrease Indent">
                <Image Source="..\Images\ParagraphDecreaseIndentation.png"></Image>
            </Button>
        </ToolBar>
        <controls:BindableRichTextBox  Grid.Row="1"
                    x:Name="mainRTB"
                    Document="{Binding Path=Document, ElementName=textEditor, Mode=TwoWay, Converter={StaticResource StringToXamlConverter}}" 
                    Margin="10" 
                    BorderBrush="Black"
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        
    </Grid>
</UserControl>
